home *** CD-ROM | disk | FTP | other *** search
- RCS_ID_C="$Id: raw_cb.c,v 1.7 1993/06/04 11:16:15 jraja Exp $";
- /*
- * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>,
- * Helsinki University of Technology, Finland.
- * All rights reserved.
- *
- * raw_cb.c --- Raw Socket Control Blocks
- *
- * Last modified: Fri Jun 4 00:39:07 1993 jraja
- *
- * HISTORY
- * $Log: raw_cb.c,v $
- * Revision 1.7 1993/06/04 11:16:15 jraja
- * Fixes for first public release.
- *
- * Revision 1.6 1993/05/16 21:09:43 ppessi
- * RCS version changed.
- *
- * Revision 1.5 1993/05/05 16:10:29 puhuri
- * Fixes for final demo.
- *
- * Revision 1.4 93/04/05 17:46:13 17:46:13 jraja (Jarno Tapio Rajahalme)
- * Changed spl storage variables to spl_t.
- * Changed every .c file to use conf.h.
- *
- * Revision 1.3 93/03/05 03:12:44 03:12:44 ppessi (Pekka Pessi)
- * Compiles with SASC. Initial test version
- *
- * Revision 1.2 93/02/25 19:52:21 19:52:21 ppessi (Pekka Pessi)
- * Added prototypes
- *
- * Revision 1.1 92/11/20 13:32:31 13:32:31 jraja (Jarno Tapio Rajahalme)
- * Initial revision
- *
- *
- */
-
- /*
- * Mach Operating System
- * Copyright (c) 1992 Carnegie Mellon University
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
- * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie Mellon
- * the rights to redistribute these changes.
- */
- /*
- * HISTORY
- * Log: raw_cb.c,v
- * Revision 2.1 92/04/21 17:13:41 rwd
- * BSDSS
- *
- *
- */
-
- /*
- * Copyright (c) 1980, 1986 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)raw_cb.c 7.11 (Berkeley) 6/28/90
- */
-
- #include <conf.h>
-
- #include <sys/param.h>
- #include <sys/systm.h>
- #include <sys/malloc.h>
- #include <sys/mbuf.h>
- #include <sys/socket.h>
- #include <sys/socketvar.h>
- #include <sys/domain.h>
- #include <sys/protosw.h>
- #include <sys/errno.h>
-
- #include <net/if.h>
- #include <net/route.h>
- #include <net/raw_cb.h>
- #include <netinet/in.h>
-
- #include <protos/kern/uipc_socket_protos.h>
- #include <protos/kern/uipc_socket2_protos.h>
-
- /* --- start moved from raw_cb.h --- */
- struct rawcb rawcb = {0}; /* head of list */
- /* --- end moved from raw_cb.h --- */
-
- /*
- * Routines to manage the raw protocol control blocks.
- *
- * TODO:
- * hash lookups by protocol family/protocol + address family
- * take care of unique address problems per AF?
- * redo address binding to allow wildcards
- */
-
- u_long raw_sendspace = RAWSNDQ;
- u_long raw_recvspace = RAWRCVQ;
-
- /*
- * Allocate a control block and a nominal amount
- * of buffer space for the socket.
- */
- int
- raw_attach(register struct socket *so,
- int proto)
- {
- register struct rawcb *rp = sotorawcb(so);
- int error;
-
- /*
- * It is assumed that raw_attach is called
- * after space has been allocated for the
- * rawcb.
- */
- if (rp == 0)
- return (ENOBUFS);
- if (error = soreserve(so, raw_sendspace, raw_recvspace))
- return (error);
- rp->rcb_socket = so;
- rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
- rp->rcb_proto.sp_protocol = proto;
- insque(rp, &rawcb);
- return (0);
- }
-
- /*
- * Detach the raw connection block and discard
- * socket resources.
- */
- void
- raw_detach(register struct rawcb *rp)
- {
- struct socket *so = rp->rcb_socket;
-
- so->so_pcb = 0;
- sofree(so);
- remque(rp);
- #ifdef notdef
- if (rp->rcb_laddr)
- m_freem(dtom(rp->rcb_laddr));
- rp->rcb_laddr = 0;
- #endif
- bsd_free((caddr_t)(rp), M_PCB);
- }
-
- /*
- * Disconnect and possibly release resources.
- */
- void
- raw_disconnect(struct rawcb *rp)
- {
-
- #ifdef notdef
- if (rp->rcb_faddr)
- m_freem(dtom(rp->rcb_faddr));
- rp->rcb_faddr = 0;
- #endif
- if (rp->rcb_socket->so_state & SS_NOFDREF)
- raw_detach(rp);
- }
-
- #ifdef notdef
- raw_bind(so, nam)
- register struct socket *so;
- struct mbuf *nam;
- {
- struct sockaddr *addr = mtod(nam, struct sockaddr *);
- register struct rawcb *rp;
-
- if (ifnet == 0)
- return (EADDRNOTAVAIL);
- rp = sotorawcb(so);
- nam = m_copym(nam, 0, M_COPYALL, M_WAITOK);
- rp->rcb_laddr = mtod(nam, struct sockaddr *);
- return (0);
- }
- #endif
-